using IrisGenerator.Common.DataTypes;
using IrisGenerator.Common.Tools;
namespace IrisGenerator.Common.Modules
{


    public partial class ModuleParameter
    {

        private System.Nullable<System.Guid> _modParId;

        private System.Nullable<System.Guid> _valTypId=new System.Guid("E7DD5BBB-F6F5-459C-BDDC-F9A70811EEF2");

        private System.Nullable<System.Guid> _modId;

        private System.Nullable<System.Guid> _modModId;

        private string _modParName;

        private string _modParDescription;

        private System.Nullable<bool> _modParMandatory;

        private Module _module;

        private Module _module2;

        private ValueType _valueType;

        private ModuleParameterInstanceCollection _moduleParameterInstanceCollection;

        public virtual System.Nullable<System.Guid> ModParId
        {
            get
            {
                return _modParId;
            }
            set
            {
                _modParId = value;
            }
        }

        public virtual string ModParName
        {
            get
            {
                return _modParName;
            }
            set
            {
                _modParName = value;
            }
        }

        public virtual string ModParDescription
        {
            get
            {
                return _modParDescription;
            }
            set
            {
                _modParDescription = value;
            }
        }

        public virtual System.Nullable<bool> ModParMandatory
        {
            get
            {
                return _modParMandatory;
            }
            set
            {
                _modParMandatory = value;
            }
        }

        public virtual Module Module
        {
            get
            {
                if ((this._module == null))
                {
                    this._module = Module.Load(this._modModId);
                }
                return this._module;
            }
            set
            {
                _module = value;
                
            }
        }

        public virtual Module Module2
        {
            get
            {
                if ((this._module2 == null))
                {
                    this._module2 = Module.Load(this._modId);
                }
                return this._module2;
            }
            set
            {
                _module2 = value;
            }
        }

        public virtual ValueType ValueType
        {
            get
            {
                if ((this._valueType == null))
                {
                    this._valueType = ValueType.Load(this._valTypId);
                }
                return this._valueType;
            }
            set
            {
                _valueType = value;
            }
        }

        public virtual ModuleParameterInstanceCollection ModuleParameterInstanceCollection
        {
            get
            {
                if ((this._moduleParameterInstanceCollection == null))
                {
                    _moduleParameterInstanceCollection = ModuleParameterInstance.Select_MODULE_PARAMETER_INSTANCE_By_MOD_PAR_ID(this.ModParId);
                }
                return this._moduleParameterInstanceCollection;
            }
        }

        private void Clean()
        {
            this.ModParId = null;
            this._valTypId = null;
            this._modId = null;
            this._modModId = null;
            this.ModParName = string.Empty;
            this.ModParDescription = string.Empty;
            this.ModParMandatory = null;
            this.Module = null;
            this.Module2 = null;
            this.ValueType = null;
            this._moduleParameterInstanceCollection = null;
        }

        private void Fill(System.Data.DataRow dr)
        {
            this.Clean();
            if ((dr["MOD_PAR_ID"] != System.DBNull.Value))
            {
                this.ModParId = ((System.Nullable<System.Guid>)(dr["MOD_PAR_ID"]));
            }
            if ((dr["VAL_TYP_ID"] != System.DBNull.Value))
            {
                this._valTypId = ((System.Nullable<System.Guid>)(dr["VAL_TYP_ID"]));
            }
            if ((dr["MOD_ID"] != System.DBNull.Value))
            {
                this._modId = ((System.Nullable<System.Guid>)(dr["MOD_ID"]));
            }
            if ((dr["MOD_MOD_ID"] != System.DBNull.Value))
            {
                this._modModId = ((System.Nullable<System.Guid>)(dr["MOD_MOD_ID"]));
            }
            if ((dr["MOD_PAR_NAME"] != System.DBNull.Value))
            {
                this.ModParName = ((string)(dr["MOD_PAR_NAME"]));
            }
            if ((dr["MOD_PAR_DESCRIPTION"] != System.DBNull.Value))
            {
                this.ModParDescription = ((string)(dr["MOD_PAR_DESCRIPTION"]));
            }
            if ((dr["MOD_PAR_MANDATORY"] != System.DBNull.Value))
            {
                this.ModParMandatory = ((System.Nullable<bool>)(dr["MOD_PAR_MANDATORY"]));
            }
        }

        public static ModuleParameterCollection Select_MODULE_PARAMETER_By_MOD_MOD_ID(System.Nullable<System.Guid> MOD_MOD_ID)
        {
            IrisGenerator.Dal.ModuleParameter dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.ModuleParameter();
                System.Data.DataSet ds = dbo.Select_MODULE_PARAMETER_By_MOD_MOD_ID(MOD_MOD_ID);
                ModuleParameterCollection collection = new ModuleParameterCollection();
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1))
                    {
                        ModuleParameter obj = new ModuleParameter();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null))
                        {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public static ModuleParameterCollection Select_MODULE_PARAMETER_By_MOD_ID(System.Nullable<System.Guid> MOD_ID)
        {
            IrisGenerator.Dal.ModuleParameter dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.ModuleParameter();
                System.Data.DataSet ds = dbo.Select_MODULE_PARAMETER_By_MOD_ID(MOD_ID);
                ModuleParameterCollection collection = new ModuleParameterCollection();
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1))
                    {
                        ModuleParameter obj = new ModuleParameter();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null))
                        {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public static ModuleParameterCollection Select_MODULE_PARAMETER_By_VAL_TYP_ID(System.Nullable<System.Guid> VAL_TYP_ID)
        {
            IrisGenerator.Dal.ModuleParameter dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.ModuleParameter();
                System.Data.DataSet ds = dbo.Select_MODULE_PARAMETER_By_VAL_TYP_ID(VAL_TYP_ID);
                ModuleParameterCollection collection = new ModuleParameterCollection();
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1))
                    {
                        ModuleParameter obj = new ModuleParameter();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null))
                        {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public static ModuleParameterCollection GetAll()
        {
            IrisGenerator.Dal.ModuleParameter dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.ModuleParameter();
                System.Data.DataSet ds = dbo.MODULE_PARAMETER_Select_All();
                ModuleParameterCollection collection = new ModuleParameterCollection();
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1))
                    {
                        ModuleParameter obj = new ModuleParameter();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null))
                        {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public static ModuleParameter Load(System.Nullable<System.Guid> MOD_PAR_ID)
        {
            IrisGenerator.Dal.ModuleParameter dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.ModuleParameter();
                System.Data.DataSet ds = dbo.MODULE_PARAMETER_Select_One(MOD_PAR_ID);
                ModuleParameter obj = null;
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    if ((ds.Tables[0].Rows.Count > 0))
                    {
                        obj = new ModuleParameter();
                        obj.Fill(ds.Tables[0].Rows[0]);
                    }
                }
                return obj;
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public virtual void Load()
        {
            IrisGenerator.Dal.ModuleParameter dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.ModuleParameter();
                System.Data.DataSet ds = dbo.MODULE_PARAMETER_Select_One(this.ModParId);
                if (GlobalTools.IsSafeDataSet(ds))
                {
                    if ((ds.Tables[0].Rows.Count > 0))
                    {
                        this.Fill(ds.Tables[0].Rows[0]);
                    }
                }
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public virtual void Insert()
        {
            IrisGenerator.Dal.ModuleParameter dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.ModuleParameter();
                dbo.MODULE_PARAMETER_Insert(this._valTypId, this.Module.ModId, this._modModId, this.ModParName, this.ModParDescription, this.ModParMandatory);
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public virtual void Delete()
        {
            IrisGenerator.Dal.ModuleParameter dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.ModuleParameter();
                dbo.MODULE_PARAMETER_Delete(this.ModParId);
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }

        public virtual void Update()
        {
            IrisGenerator.Dal.ModuleParameter dbo = null;
            try
            {
                dbo = new IrisGenerator.Dal.ModuleParameter();
                  dbo.MODULE_PARAMETER_Update(this.ModParId, this._valTypId, this.Module.ModId, this._modModId, this.ModParName, this.ModParDescription, this.ModParMandatory);
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                if ((dbo != null))
                {
                    dbo.Dispose();
                }
            }
        }
    }
}
